<template>
    <div>
  <h2>查看待审批</h2><br>
  <table>
  <tr>
      <td>
  <el-form-item label="合同标题：" style="font-size: 20px;float: right;" prop="contractTitle">
          <el-input v-model="form.contractTitle" style="width: 300px;height: 40px;" :disabled="true"
          placeholder="请输入合同标题" clearable />
        </el-form-item>
    
      </td>
      <td>
        <el-form-item label="对方单位" style="font-size: 20px;float: right;" prop="contractTitle">
          <el-input v-model="form.unit" style="width: 300px;height: 40px;" :disabled="true"
          placeholder="请输入对方单位" clearable />
        </el-form-item>
      </td>
    </tr>
    <tr>
      <td>
        <el-form-item label="对方负责人：" style="font-size: 20px;float: right;" prop="contractTitle">
          <el-input v-model="form.personCharge" style="width: 300px;height: 40px;" :disabled="true"
          placeholder="请输入对方负责人" clearable />
        </el-form-item>
      </td>
      <td>
        <el-form-item label="合同类型：" style="font-size: 20px;float: right;" prop="contractTitle">
          <el-input v-model="form.contractType" style="width: 300px;height: 40px;" :disabled="true"
          placeholder="请输入合同类别" clearable />
        </el-form-item>
      </td>
    </tr>
    <tr>
      <td>
        <el-form-item label="签订时间：" style="font-size: 20px;float: right;" prop="contractTitle">
          <el-date-picker v-model="form.dateofSigning" type="date"  :disabled="true"
            placeholder="请选择签订时间" clearable  style="width: 300px;height: 40px;"/>
        </el-form-item>
      </td>
      <td>
        <el-form-item label="经办人：" style="font-size: 20px;float: right;" prop="contractTitle">
          <el-input v-model="form.attn" style="width: 300px;height: 40px;" :disabled="true"
          placeholder="请输入经办人" clearable />
        </el-form-item>
      </td>
    </tr>
    <tr>
      <td>
        <el-form-item label="合同金额：" style="font-size: 20px;float: right;">
          <el-input v-model="form.contractAmount" style="width: 300px;height: 40px;" :disabled="true"
          placeholder="请输入合同金额" clearable />
        </el-form-item>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <el-form-item label="合同标的或项目说明" 
          style="font-size: 20px;width: 970px;height: 100px;float: right;" >
        <el-input v-model="form.contractNote" type="textarea" style="font-size: 20px;width: 970px;height: 100px;" :disabled="true"></el-input>
        </el-form-item>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <el-form-item label="合同主要条款/边更条款" 
          style="font-size: 20px;width: 970px;height: 100px;float: right;">
        <el-input v-model="form.contractTerms" type="textarea" style="font-size: 20px;width: 970px;height: 180px;" :disabled="true"></el-input>
        </el-form-item>
        
      </td>
    </tr>
    <tr >
      <td style="font-size: 20px;">合同文本(附件)：</td>
      <td>
        <el-upload
  v-model:file-list="fileList"
  class="upload-demo"
  action="http://10.223.8.15:8000/hwrite/api/Contract/Upfile"
  multiple
 :disabled="true"
  :limit="30000"
  :on-success="handleSuccess"
>
</el-upload>
        <span>（单个附件最大支持20M，支持：PDF、Word、Excel、Txt格式）</span> 
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <el-form-item label="审批备注:"  
          style="font-size: 20px;width: 970px;height: 100px;float: right;">
          <el-input v-model="from.approvalNotes" type="textarea" style="font-size: 20px;width: 970px;height: 200px;" ></el-input>
        </el-form-item>
         </td>
    </tr>
    <tr>
      <td colspan="2">
        <el-form-item label="转批人:" 
          style="font-size: 20px;width: 970px;height: 5px;float: right;">
          <el-select v-model="from.subgrantor" placeholder="请选择名字" style="width: 240px;"  >
      <el-option v-for="item in username" :key="item.id" :label="item.name" :value="item.name"/>
    </el-select>
        </el-form-item>
        
      </td>
    </tr>
</table><br><br>
    <tr align="center">
      
      <el-button type="primary" @click="Submit" 
        style="width: 150px;height: 50px;">通过并转批</el-button>
        <el-button  @click="Cancel" style="width: 150px;height: 50px;"
        >拒绝</el-button>
        <el-button type="success" @click="onSubmit" 
        style="width: 150px;height: 50px;">通过并终止审批</el-button>
 </tr>
 </div>
</template>
  
<script setup lang='ts'>
   import axios  from 'axios';
   import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
 import { ref, reactive, onMounted } from 'vue'; 
  import { useRouter, useRoute } from 'vue-router';
  const route = useRoute();
  const router = useRouter();
  onMounted(() => {
    backfill()
    getUserSelect()
  })
//审批表
const from=reactive({
    approvalResult:'',
    approvalNotes:'',
    approver:'',
    contractId:'',
    subgrantor:''
})
  const form=reactive({
      contractId:route.query.ContractId,
      contractTitle:'',
      unit:'',
      personCharge:'',
     contractNumber:'',
      contractType:'',
      dateofSigning:'',
      attn:'',
      contractAmount:'',
      contractNote:'',
      contractTerms:'',
      contractText:'',
      ccontractStatus:0,
      contractClassification:3,//合同分类
 updatedBy:'admin',//更新人
  updatedDate:new Date(),//更新时间
  createdBy:'admin',//创建人
  createdDate:new Date(),//创建时间
  deletedBy:'admin',//删除人
  deletedDate:new Date(),//删除时间
  })
    //用户名称列表
    const username=ref([])
const UserSelectData:any=ref([])
const getUserSelect=()=>{
  axios.get('http://1.117.93.87:8000/rbacdu/api/User/UserSelectShow').then(res=>{
    //console.log(res);
    UserSelectData.value = res.data.data
    username.value =UserSelectData.value.filter(o=>o.name!=localStorage.getItem('username'));
    console.log(username.value);

  }).catch(err=>{
    console.log(err);
    
  })    
}
//反填
const backfill = () => {
axios.get('/hread/api/ContractRead/BackfillTshowContract', {
      params: {
        ContractId: route.query.ContractId
      }
    }).then(res => {
    console.log(res.data.data)
      form.contractTitle = res.data.data.contractTitle
      form.unit = res.data.data.unit
      form.personCharge = res.data.data.personCharge
      form.contractNumber = res.data.data.contractNumber
      form.contractType = res.data.data.contractType
      form.dateofSigning = res.data.data.dateofSigning
      form.attn = res.data.data.attn
      form.contractAmount = res.data.data.contractAmount
      form.contractNote = res.data.data.contractNote
      form.contractTerms = res.data.data.contractTerms
      form.contractText = res.data.data.contractText
      form.ccontractStatus = res.data.data.ccontractStatus
      form.contractClassification = res.data.data.contractClassification
      form.updatedBy=res.data.data.updatedBy
    form.updatedDate=res.data.data.updatedDate
    form.createdBy=res.data.data.createdBy
    form.createdDate=res.data.data.createdDate
    form.deletedBy=res.data.data.deletedBy
    form.deletedDate=res.data.data.deletedDate
      localStorage.setItem('contractText2',res.data.data.contractText)
      kk()
  })
  
}
//上传文件
const handleSuccess=(any:any)=>{
console.log(any);
form.contractText=any;
}

const fileList=ref()
const kk=()=>{
const fileLists = ref([
{
      name: localStorage.getItem('contractText2'),
      url:'/hread/wwwroot/file/'+localStorage.getItem('contractText2'),
}
])
fileList.value=fileLists.value
console.log(fileList.value)
}

//同意
const onSubmit = () => {
  let hh={
    approvalResult:"同意",
    approvalNotes:from.approvalNotes,
    approver:localStorage.getItem('username'),
    contractId:route.query.ContractId,
    subgrantor:from.subgrantor,
}
 axios.post('/hwrite/api/Contract/CrerateAppro',hh).then(res=>{
        if(res.data.data>0){
         ElMessage({
           message: '已通过',
          type: 'success',
        })
        router.push('/TContract')
       }else{
         ElMessage.error('修改失败')
        }
    })
}
//转批
const Submit=()=>{
  let hh={
    approvalResult:"同意并转批",
    approvalNotes:from.approvalNotes,
    approver:localStorage.getItem('username'),
    contractId:route.query.ContractId,
    subgrantor:from.subgrantor,
}
 axios.post('/hwrite/api/Contract/CrerateAppro',hh).then(res=>{
        if(res.data.data>0){
         ElMessage({
           message: '已通过并转批',
          type: 'success',
        })
        router.push('/TContract')
       }else{
         ElMessage.error('修改失败')
        }
    })
}
//拒绝
const Cancel=()=>{
 
let hh={
    approvalResult:"拒绝",
    approvalNotes:from.approvalNotes,
    approver:localStorage.getItem('username'),
    contractId:route.query.ContractId,
    subgrantor:from.subgrantor,
}
axios.post('/hwrite/api/Contract/CrerateAppro',hh).then(res=>{
        if(res.data.data>0){
         ElMessage({
           message: '已拒绝',
          type: 'success',
        })
        router.push('/TContract')
       }else{
         ElMessage.error('修改失败')
        }
    })

}
</script>
  
<style>
  
</style>